<!--
 * @Author: your name
 * @Date: 2021-09-24 10:52:51
 * @LastEditTime: 2021-12-10 19:15:20
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: \jingfeng-web\src\components\overMettingReply\overMettingReply.vue
-->
<template>
  <div>
    <CommonDialog
      :title="replyTitle"
      width="75%"
      v-bind:dialogVisible="replyDialogVisible"
      @on-change-dialogVisible="replyDialogChange"
      class="suspend"
      top="10vh"
    >
      <template #body>
        <el-form
          class="overReplyForm"
          ref="overReplyForm"
          :rules="overReplyFormRules"
          :model="overReplyForm"
          label-width="150px"
          label-position="top"
        >
          <el-row>
            <el-col :span="24">
              <!-- <el-form-item v-if="meetingVersion == 0" label="上会原因/不上会原因" prop="reason">
                <el-input
                  type="textarea"
                  class="solutionVersion"
                  v-model="overReplyForm.reason"
                  placeholder="请填写原因"
                />

              </el-form-item> -->
              <el-form-item    label="本周会议讨论内容" prop="discussionContent">
                <el-input
                  type="textarea"
                  class="solutionVersion"
                  v-model="overReplyForm.discussionContent"
                  placeholder="本周会议讨论内容"
                />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="25">
              <!-- scope.row.autoCreate ==false -->
              <!-- v-if="meetingVersion == 0&&autoCreate" -->
            <el-col :span="12" >
              <el-form-item class="isDing" prop="continueMeetingTag" label="是否继续上会">
                <el-radio-group v-model="overReplyForm.continueMeetingTag">
                  <el-radio :disabled="meetingVersion==0&&!autoCreate" :label="true" class="firstRadio">继续上会</el-radio>
                  <el-radio :disabled="meetingVersion==0&&!autoCreate" :label="false">转线下跟进</el-radio>
                </el-radio-group>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="主负责人" prop="masterId">
                <el-select v-model="overReplyForm.masterId" @change="changeMaster" clearable filterable class="elementSlect">
                  <el-option
                    v-for="(items, inds) in productUserList"
                    :key="inds"
                    :label="items.name"
                    :value="items.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row :gutter="25">
            <el-col :span="12">
              <el-form-item label="其他负责人" prop="otherPrincipalUserId">
                <el-select
                  v-model="overReplyForm.otherPrincipalUserId"
                  @change="selectIdChange"
                  class="elementSlect"
                  filterable
                  clearable
                  multiple
                >
                  <el-option
                    v-for="(items, inds) in userList"
                    :key="inds"
                    :label="items.name"
                    :value="items.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="申请人" prop="applicantId">
                <el-select v-model="overReplyForm.applicantId" @change="chnageApplicant" class="elementSlect" clearable filterable>
                  <el-option
                    v-for="(items, inds) in productUserList"
                    :key="inds"
                    :label="items.name"
                    :value="items.id"
                  ></el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="remark" label="备注">
                <el-input type="textarea" v-model="overReplyForm.remark" class="replyNote" />
              </el-form-item>
            </el-col>
          </el-row>
        </el-form>
      </template>

      <template #dialog_footer>
        <el-button class="submitCancel" @click="replyCancel">取 消</el-button>
        <el-button type="primary" @click="replyValid">保存</el-button>
      </template>
    </CommonDialog>
  </div>
</template>

<script>
import CommonDialog from '@/components/commonDialog/commonDialog.vue'
import { DelateMetting } from '@/api/delateMeeting/server'
import { FeedBack } from '@/api/feedBack/server'
// import socialUpload from '../socialUpload/socialUpload.vue'

export default {
    name: '',
    components: {
        CommonDialog
    // socialUpload
    },
    props: {
        replyTitle: {
            type: String,
            default: '回复'
        }
    },
    data() {
        return {
            userList: [],
            VofVersion: '',
            replyDialogVisible: false,
            productUserList: [],
            meetingFeedBackTaskId: '',
            meetingVersion: null,
            autoCreate: '',
            mainID: '',
            masterName: '',
            feedBackNumber: '',
            taskNumber: '',
            otherPrincipalUserName: [],
            applicantName: '',
            overReplyForm: {
                discussionContent: '', // 本周会议讨论内容
                continueMeetingTag: true,
                masterId: '',
                master: '',
                otherPrincipalUserId: [],
                otherPrincipalUserName: [],
                applicantId: '',
                applicantName: '',
                remark: ''
            },
            overReplyFormRules: {
                discussionContent: [
                    {
                        required: true,
                        message: '请输入上会原因/不上会原因',
                        trigger: 'blur'
                    }
                ],
                discussionContent2: [
                    {
                        required: true,
                        message: '请输入本周会议讨论内容/不上会原因',
                        trigger: 'blur'
                    }
                ],
                reason: [
                    {
                        required: true,
                        message: '请输入本周会议讨论内容/不上会原因',
                        trigger: 'blur'
                    }
                ],
                otherPrincipalUserId: [
                    {
                        required: false,
                        message: '请选择其他责任人',
                        trigger: 'change'
                    }
                ],
                masterId: [
                    {
                        required: true,
                        message: '请选择主责任人',
                        trigger: 'change'
                    }
                ],
                applicantId: [
                    {
                        required: true,
                        message: '请选择申请人',
                        trigger: 'change'
                    }
                ]
            }
        }
    },
    computed: {},
    watch: {},
    created() {},
    mounted() {},
    methods: {
        changeMaster(v) {
            let names = ''
            this.productUserList.forEach((element) => {
                if (element.id === v) {
                    names = element.name
                }
            })

            this.overReplyForm.master = names
        },
        chnageApplicant(v) {
            let names = ''
            this.productUserList.forEach((element) => {
                if (element.id === v) {
                    names = element.name
                }
            })

            this.overReplyForm.applicantName = names
        },
        selectIdChange(e) {
            console.log(e)
            const idArr = []
            this.userList.forEach(element => {
                e.forEach(els => {
                    if (element.id == els) {
                        idArr.push(element.name)
                    }
                })
            })
            this.overReplyForm.otherPrincipalUserName = idArr
        },
        show(objStr) {
            this.replyDialogVisible = true
            const row = JSON.parse(objStr)
            console.log(row)
            this.getUserListById(row.productId)
            this.meetingFeedBackTaskId = row.meetingFeedBackTaskId
            this.meetingVersion = row.meetingversion
            this.autoCreate = row.autoCreate

            if (this.meetingVersion == 0) {
                this.VofVersion = 'V1'
            } else {
                this.VofVersion = 'V2'
            }
            this.getAllUserList()
            this.replayFromDetail(row.meetingFeedBackTaskId, row.meetingversion == 0 ? 'V1' : 'V2')
        },
        /**
     * @description:获取指派人列表
     */
        async getAllUserList() {
            try {
                const result = await FeedBack.GetAllUserAsync()
                if (result.success) {
                    this.userList = result.data
                }
            } catch (err) {
                console.log(err)
            }
        },
        replyDialogChange() {
            this.$refs['overReplyForm'].resetFields()
            this.replyDialogVisible = false
        },
        replyCancel() {
            this.$refs['overReplyForm'].resetFields()
            this.replyDialogVisible = false
        },
        // 获得负责人下拉
        async getUserListById(productId) {
            try {
                const result = await FeedBack.GetListItemAsync({ id: productId })
                if (result.success) {
                    this.productUserList = result.data
                }
            } catch (err) {
                console.log(err)
            }
        },
        // 详细信息回显示
        async replayFromDetail(_id, version) {
            try {
                const result = await DelateMetting.GetVersionMeetingInfo({ id: _id, version: version })
                if (result.success) {
                    this.overReplyForm = result.data
                    this.taskNumber = result.data.taskNumber
                    const otherList = result.data.otherPrincipalUserName
                    this.feedBackNumber = result.data.feedBackNumber
                    this.mainID = result.data.id
                    this.meetingVersion = result.data.meetingVersion
                    const isHere = this.productUserList.findIndex(item => item.id === result.data.applicantId)
                    if (isHere === -1) {
                        this.overReplyForm.applicantId = ''
                        this.overReplyForm.applicantName = ''
                    }
                    if (otherList && otherList.length > 0) {
                        this.overReplyForm.otherPrincipalUserName = otherList
                    } else {
                        this.overReplyForm.otherPrincipalUserName = []
                    }
                    const otherList2 = result.data.otherPrincipalUserId
                    if (otherList2 && otherList2.length > 0) {
                        this.overReplyForm.otherPrincipalUserId = otherList2
                    } else {
                        this.overReplyForm.otherPrincipalUserId = []
                    }
                } else {
                    this.$message.error(result.message)
                }
            } catch (err) {
                console.log(err)
                // this.$message.error('服务器异常');
            }
        },
        // 确认回复
        async confirmReply() {
            this.overReplyForm.version = this.meetingVersion
            try {
                const result = await DelateMetting.SaveAssociate(this.overReplyForm)
                if (result.success) {
                    this.replyDialogVisible = false
                    this.$message.success('保存成功')
                    this.$emit('refreshPage')
                } else {
                    this.$message.error(result.message)
                }
            } catch (err) {
                console.log(err)
                this.$message.error('服务器异常')
            }
        },
        // 回复之前验证
        replyValid() {
            console.log(this.overReplyForm)
            this.$refs['overReplyForm'].validate(valid => {
                if (valid) {
                    this.confirmReply()
                } else {
                    return false
                }
            })
        },
        getUpdateContent(Value) {
            this.overReplyForm.discussionContent = Value
        }
    }
}
</script>

<style scoped lang="less">
.elementSlect {
  width: 100%;
  height: 35px;
}
::v-deep .ql-formats .ql-image {
  display: none;
}
// 重置富文本框的高度
::v-deep .ql-editor {
  height: 160px !important;
  overflow: auto;
}
</style>
